package com.ruoyi.web.controller.danger;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.entity.AlarmPerimeterDev;
import com.ruoyi.system.service.AlarmPerimeterDevService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (电子围栏)表控制层
 */
@Slf4j
@RestController
@RequestMapping("alarmPerimeterDev")
public class AlarmPerimeterDevController extends BaseController {

    @Resource
    private AlarmPerimeterDevService alarmPerimeterDevService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @GetMapping("/list")
    public TableDataInfo queryByPage(AlarmPerimeterDev alarmPerimeterDev) {
        startPage();
        Page<Object> localPage = PageUtils.getLocalPage();
        int pageNum = localPage.getPageNum();
        int pageSize = localPage.getPageSize();
        String sendGet = HttpUtils.sendGet("http://192.168.18.158:39097/jdbc/alarmPerimeterDev/list?pageSize=" + pageSize + "&pageNumber=" + (pageNum - 1) * pageSize, null);
        log.info("==============电子围栏==========={}", JSON.toJSONString(sendGet));
        return JSON.parseObject(sendGet, TableDataInfo.class);
    }

    /**
     * 通过主键查询单条数据
     *
     * @return 单条数据
     */
    @GetMapping("{devsn}")
    public AjaxResult queryById(@PathVariable("devsn") String devsn) {
        return AjaxResult.success(this.alarmPerimeterDevService.queryById(devsn));
    }

    /**
     * 新增数据
     *
     * @param alarmPerimeterDev 实体
     * @return 新增结果
     */
    @PostMapping("/create")
    public AjaxResult add(AlarmPerimeterDev alarmPerimeterDev) {
        return AjaxResult.success(this.alarmPerimeterDevService.insert(alarmPerimeterDev));
    }

    /**
     * 编辑数据
     *
     * @param alarmPerimeterDev 实体
     * @return 编辑结果
     */
    @PostMapping("/update")
    public AjaxResult edit(AlarmPerimeterDev alarmPerimeterDev) {
        return AjaxResult.success(this.alarmPerimeterDevService.update(alarmPerimeterDev));
    }

    /**
     * 删除数据
     *
     * @return 删除是否成功
     */
    @GetMapping("/delete")
    public AjaxResult deleteById(String devsn) {
        return AjaxResult.success(this.alarmPerimeterDevService.deleteById(devsn));
    }

}

